﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Enterprise.Model.Jihuabu;
using Enterprise.Data.Jihuabu;
using System.Data;

namespace Enterprise.Service.Jihuabu
{
    /// <summary>
    /// M01模块-进度表
    /// </summary>
    public class M01JDBService
    {
        private readonly Enterprise.Data.Jihuabu.M01_JDBData dal=new Enterprise.Data.Jihuabu.M01_JDBData();
        public M01JDBService()
		{}
		#region  BasicMethod
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string AFEBH,string WCSJ)
		{
			return dal.Exists(AFEBH,WCSJ);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(M01_JDBEntity model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(M01_JDBEntity model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string AFEBH,string WCSJ)
		{
			
			return dal.Delete(AFEBH,WCSJ);
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public M01_JDBEntity GetModel(string AFEBH,string WCSJ)
		{
			
			return dal.GetModel(AFEBH,WCSJ);
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
        
        /// <summary>
        /// 根据SQL语句获取数据表
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public DataSet GetListbySQL(string sql)
        {
            return dal.GetListbySQL(sql);
        }

        public void ExcuteUpdateSql(string sql)
        {
            dal.ExcuteUpdateSql(sql);
        }
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<M01_JDBEntity> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<M01_JDBEntity> DataTableToList(DataTable dt)
		{
			List<M01_JDBEntity> modelList = new List<M01_JDBEntity>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				M01_JDBEntity model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = dal.DataRowToModel(dt.Rows[n]);
					if (model != null)
					{
						modelList.Add(model);
				}
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  BasicMethod
		#region  ExtensionMethod

		
        /// <summary>
        /// 获取所有已录入周期
        /// </summary>
        /// <returns></returns>
        public DataSet getRiqiList(string strWhere)
        {
            return dal.getRiqiList(strWhere);
        }


        
        /// <summary>
        /// 从项目表创建数据
        /// </summary>
        /// <param name="rq"></param>
        public void CreateDataFromXmb(string rq)
        {
            dal.CreateDataFromXmb(rq);
        }

        #endregion  ExtensionMethod

        public bool isNew(string rq)
        {
            return dal.isNew(rq);
        }
    }
}
